package oocl.eshop.ui.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oocl.eshop.po.Merchant;
import oocl.eshop.service.MerchantManager;
import oocl.eshop.service.impl.MerchantManagerImpl;

/**
 * Servlet implementation class UpdateMerchantServlet
 */
public class UpdateMerchantServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	MerchantManager merchantManager = new MerchantManagerImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateMerchantServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub	
		Merchant merchant = (Merchant) request.getAttribute("thisMerchant");	
		System.out.println(merchant);
		int i = merchantManager.updateMerchant(merchant);
		if(i==0)
		{
			System.out.println("Merchant update Error");
		}
		HttpSession session = request.getSession();
		session.setAttribute("merchant", merchantManager.findMerchantById(merchant.getmId()));
		request.getRequestDispatcher("homePage.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
